﻿using System.Collections.Generic;
using System.Web.UI.WebControls;
using ReadyApps.Data;
using ReadyApps.Data.Wiki;

namespace ReadyApps.Wiki.Views
{
    class NewPageView : EditView
    {
        #region Variables and Constants

        private const string PAGE_NAME_CONTROL_ID = "txtPageName";

        private TextBox txtPageName;

        #endregion

        #region Constructor

        public NewPageView(int wikiPageID, string requestBaseFolder, WikiControlSettings wikiControlSettings,
            IWikiDataProvider wikiDataProvider, IWikiUrlManager wikiUrlManager, IWikiSecurityManager wikiSecurityManager)
            : base(wikiPageID, requestBaseFolder, PageDetails.Empty, wikiControlSettings, wikiDataProvider, wikiUrlManager, wikiSecurityManager)
        {
            headerText = "New Page";
        }

        #endregion

        #region Method Overrides

        protected override PageContent GetPageData()
        {
            return null;
        }

        protected override string GetPageTitle(PageContent data)
        {
            return "New Page";
        }

        protected override string GetEditableText(PageContent content)
        {
            return string.Empty;
        }

        protected override IEnumerable<AvailablePageLink> GetAvailablePageLinks()
        {
            return dataProvider.GetAvailablePageLinks(baseFolder, pageID, false);
        }

        protected override SavePageEventArgs GetSavePageEventArgs()
        {
            return new SavePageEventArgs(txtPageName.Text, txtPageTitle.Text, editor.Text);
        }

        protected override List<EditView.TextBoxContainer> GetTextBoxContainers()
        {
            List<EditView.TextBoxContainer> boxes = new List<TextBoxContainer>();

            txtPageName = new TextBox();
            txtPageName.ID = PAGE_NAME_CONTROL_ID;
            boxes.Add(new TextBoxContainer("Page Name", txtPageName, null));
            boxes.AddRange(base.GetTextBoxContainers());

            return boxes;
        }

        #endregion
    }
}
